<?php
namespace app\cms\loglic;

use app\common\loglic\Update;

class Upgrade extends Update
{
    //更新应用状态
    public function status()
    {
        \daicuo\Apply::updateStatus('cms', 'enable');
        
        return true;
    }
    
    //更新打包信息
    public function pack()
    {
        if(config('common.apply_module') != 'cms'){
            return true;
        }
        
        return \daicuo\Op::write([
            'apply_name'    => '呆错文章管理系统',
            'apply_module'  => 'cms',
            'apply_version' => config('apply.version'),
            'apply_rely'    => '',
        ], 'common', 'config', 'system', 0, 'yes');
    }
    
    //更新后台菜单
    public function lang()
    {
        model('common/Lang','loglic')->unInstall('cms');
        
        model('cms/Install','loglic')->lang();
        
        return true;
    }
    
    //更新后台菜单
    public function menu()
    {
        model('common/Menu','loglic')->delete([
            'module' => 'cms',
            'name'   => '页面配置',
        ]);
        
        model('common/Menu','loglic')->delete([
            'module' => 'cms',
            'name'   => '频道设置',
        ]);
        
        model('common/Menu','loglic')->install([
            [
                'term_name'   => '页面配置',
                'term_slug'   => 'cms/config/index',
                'term_info'   => 'fa-gear',
                'term_module' => 'cms',
                'term_order'  => 2,
            ],
            [
                'term_name'   => '频道设置',
                'term_slug'   => 'cms/config/system',
                'term_info'   => 'fa-gears',
                'term_module' => 'cms',
                'term_order'  => 1,
            ],
        ],'文章');
        
        return true;
    }
    
    //更新前台菜单
    public function navs()
    {
        return true;
    }
    
    //添加采集规则
    public function collect()
    {
        config('common.validate_name', false);
        
        model('cms/Collect','loglic')->write([
            'collect_name'     => '故事大全',
            'collect_url'      => 'http://api.daicuo.cc/gushi/',
            'collect_token'    => '',
            'collect_category' => '',
        ]);
        
        return true;
    }
    
    //升级框架脚本
    public function frame(){
        return true;
    }
}